package com.atguigu.edu.publisher.mapper;

import com.atguigu.edu.publisher.beans.UserChangeCtPerType;
import com.atguigu.edu.publisher.beans.UserPageCt;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserStatsMapper {
    @Select("select \n" +
            "'home'  page_id,\n" +
            "sum(home_uv_ct)        uvCt  \n" +
            "from dws_traffic_home_detail_page_view_window\n" +
            "where toYYYYMMDD(stt) = #{date}\n" +
            "union all\n" +
            "select \n" +
            "'course_detail' page_id,\n" +
            "sum(course_detail_uv_ct) uvCt\n" +
            "from dws_traffic_home_detail_page_view_window\n" +
            "where toYYYYMMDD(stt) = #{date}\n" +
            "union all\n" +
            "select 'cart' page_id,\n" +
            "sum(cart_add_uu_ct) uvCt\n" +
            "from dws_trade_cart_add_uu_window\n" +
            "where toYYYYMMDD(stt) = #{date}\n" +
            "union all\n" +
            "select 'trade' page_id,\n" +
            "sum(order_user_count) uvCt\n" +
            "from dws_trade_order_window\n" +
            "where toYYYYMMDD(stt) = #{date}\n" +
            "union all\n" +
            "select 'payment' page_id,\n" +
            "sum(payment_suc_user_count) uvCt\n" +
            "from dws_trade_payment_suc_window\n" +
            "where toYYYYMMDD(stt) = #{date};")
    List<UserPageCt> selectUvByPage(@Param("date") Integer date);

    @Select("select \n" +
            "'backCt' type,\n" +
            "sum(back_ct) back_ct\n" +
            "from dws_user_user_login_window\n" +
            "where toYYYYMMDD(stt)=#{date}\n" +
            "union all \n" +
            "select \n" +
            "'activeUserCt' type,\n" +
            "sum(uu_ct) uu_ct\n" +
            "from dws_user_user_login_window\n" +
            "where toYYYYMMDD(stt)=#{date}\n" +
            "union all \n" +
            "select \n" +
            "'newUserCt' type,\n" +
            "sum(register_ct) register_ct\n" +
            "from dws_user_user_register_window\n" +
            "where toYYYYMMDD(stt)=#{date};")
    List<UserChangeCtPerType> selectUserChangeCtPerType(@Param("date") Integer date);
}
